﻿using CloudMailShared;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Net.Mail;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;

namespace UnitTests
{
    
    
    /// <summary>
    ///This is a test class for SerializableMailMessageTest and is intended
    ///to contain all SerializableMailMessageTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SerializableMailMessageTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for SerializableMailMessage Constructor
        ///</summary>
        [TestMethod()]
        public void SerializableMailMessageConstructorTest()
        {
            string from = "someone@from.com";
            string to = "somewhere@to.com";
            SerializableMailMessage target = new SerializableMailMessage(from, to);

            Assert.AreEqual(target.From.ToString(), "someone@from.com");
            Assert.AreEqual(target.To.ToString(), "somewhere@to.com");
        }


        /// <summary>
        ///A test for SerializableMailMessage Constructor
        ///</summary>
        [TestMethod()]
        public void SerializableMailMessageConstructorTest1()
        {
            string from = "someone@from.com";
            string to = "somewhere@to.com";
            string subject = "subject";
            string body = "body";
            SerializableMailMessage target = new SerializableMailMessage(from, to, subject, body);

            Assert.AreEqual(target.From.ToString(), "someone@from.com");
            Assert.AreEqual(target.To.ToString(), "somewhere@to.com");
            Assert.AreEqual(target.Subject, "subject");
            Assert.AreEqual(target.Body, "body");
        }

        /// <summary>
        ///A test for basic errors in the serialization process
        ///</summary>
        [TestMethod()]
        public void SerializeDeserializeTest()
        {
            SerializableMailMessage target = new SerializableMailMessage(
                "from@somewhere.com",
                "to@somewhere.com",
                "A subject",
                "A body.");

            SerializableMailMessage target2 = null;

            //XmlWriter writer = null; // TODO: Initialize to an appropriate value
            //target.WriteXml(writer);
            XmlSerializer mailMessageSerializer = new XmlSerializer(typeof(SerializableMailMessage));

            using (System.IO.MemoryStream stream = new System.IO.MemoryStream(1024))
            {
                mailMessageSerializer.Serialize(stream, target);
                stream.Position = 0;
                target2 = ( SerializableMailMessage) mailMessageSerializer.Deserialize(stream);
            }

            Assert.AreEqual(target2.From.ToString(), "from@somewhere.com");
            Assert.AreEqual(target2.To.ToString(), "to@somewhere.com");
            Assert.AreEqual(target2.Subject, "A subject");
            Assert.AreEqual(target2.Body, "A body.");
        }
    }
}
